/*
 *  Copyright (C) 2011  social-tourist.org
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.socialtourist.web.shared.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(detachable="true")
public class SocialProject implements Serializable {
	
	private static final long serialVersionUID = 1L;

	public static SocialProject create(String name, int x, int y)
	{
		SocialProject project = new SocialProject();
		project.setName(name);
		project.setX(x);
		project.setY(y);
		return project;
	}
	
	public static SocialProject create(String name, int x, int y, Need... needs)
	{
		SocialProject project = create(name, x, y);
		
		for (Need need : needs) {
			project.needs.add(need);
		}
		return project;
	}
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;
	
	@Persistent
	private int x;
	
	@Persistent
	private int y;
	
	@Persistent
	private String locationString;

	@Persistent
	private String name;

	@Persistent
	private Long image1;
	
	@Persistent
	private Long image2;
	
	/** If set to false, the project is not displayed anymore. */ 
	@Persistent
	private boolean isActive;
	
	public Long getImage1() {
		return image1;
	}

	public void setImage1(Long image1) {
		this.image1 = image1;
	}

	public Long getImage2() {
		return image2;
	}

	public void setImage2(Long image2) {
		this.image2 = image2;
	}
	@Persistent
	private String description;
	
	@Persistent
	private ProjectCategory category;
	
	@Persistent(mappedBy="project", defaultFetchGroup = "true")
	private List<Need> needs; 

	public SocialProject()
	{
		needs = new ArrayList<Need>();	
		isActive = true;
	}
	
	public ProjectCategory getCategory() {
		return category;
	}

	public String getDescription() {
		return description;
	}

	public String getLocationString() {
		return locationString;
	}

	public String getEncodedKey() {
		return encodedKey;
	}

	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	public void setNeeds(List<Need> needs) {
		this.needs = needs;
	}

	public String getName() {
		return name;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setCategory(ProjectCategory category) {
		this.category = category;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setLocationString(String locationString) {
		this.locationString = locationString;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public void setY(int y) {
		this.y = y;
	}

	public List<Need> getNeeds() {
		return needs;
	}

}
